<?php
/**
 * Created by PhpStorm.
 * User: tom_xia
 * Date: 2018/5/29
 * Time: 15:09
 * 提交审核
 */
require_once dirname(__DIR__)."/login_filter.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\model\Video;
use app\model\Music;
$my_uuid=$Auth["uuid"];
//接收参数
if(empty($_REQUEST["video_uuid"])  || empty($_REQUEST["audio_url"])){
    Response::output(-1,"参数错误");
}
$materialId = $_REQUEST["video_uuid"];//原始素材的视频的uuid
$audioUrl = $_REQUEST["audio_url"];//用户配音
$channelCode = isset($_REQUEST["channel_code"]) ? $_REQUEST["channel_code"] :"";

$redis = SysResource::getRedis();
$redisKey = REDIS_PREFIX."peiyin_submit_video_".$material_id;
$videoInfo = $redis->get($redisKey);

if(!empty($videoInfo)){
    $videoInfo = json_decode($videoInfo,true);
}else{
    $videoModel = new Video(SysResource::getDB(false));
    $videoInfo = $videoModel->getInfo(["video_uuid"=>$materialId],"video_id,video_uuid,video_small_pic,cut_music_url,transcode_video_no_music_url,video_time,video_desc,video_join_type,video_join_sub,width,height");
    if(empty($videoInfo)){
        Response::output(-1,"无效的请求");
    }
}

try{
    $db = SysResource::getDB(true);
    $videoModel = new Video($db);
    $material_id = Tools::UUID();//这是生成任务id
    $db->insert("user_material",[
        "uuid"=>$my_uuid,//用户uuid
        "material_id"=>$material_id,//任务id
        "video_uuid"=>$materialId,//原始素材uuid
        "nick_name"=>$Auth["nick_name"],//用户呢称
        "nick_pic"=>$Auth["nick_pic"],
        "pic"=>$videoInfo["video_small_pic"],
        "video_desc"=>$videoInfo["video_desc"],
        "duration"=>$videoInfo["video_time"],
        "join_type"=>$videoInfo["video_join_type"],
        "join_type_sub"=>$videoInfo["video_join_sub"],
        "no_music_video_url"=>$videoInfo["transcode_video_no_music_url"],
        "music"=>$videoInfo["cut_music_url"],
        "width2"=>$videoInfo["width"],
        "height2"=>$videoInfo["height"],
        "first_pic3"=>$videoInfo["first_pic1"],
        "audio_url"=>$audioUrl,
        "add_time"=>date("Y-m-d H:i:s"),
        "is_save"=>1,
    ]);
    $db->update("video",["dub_num"=>"!dub_num+1"],["video_uuid"=>$materialId]);

    $dyKeyPrefix = REDIS_PREFIX."material_dy_";
    $dyKey = $dyKeyPrefix.$materialId;
    $redis->zAdd($dyKey,intval(microtime(true)*1000),$Auth["user_uuid"]);
    //动态截断
    $redis->zRemRangeByRank($dyKey,10,-1);
    Response::output(0,"提交成功",["job_id"=>$material_id]);
}catch (Exception $e){
    Response::output(-1,"提交失败,请重试");
}







